import 'package:flutter/foundation.dart';
import 'package:syria_sports/core/utils/show_toast.dart';
import 'package:syria_sports/widgets/app_bar/outline_icon_button.dart';

import '../../../data/models/auth/user.dart';
import '../../../dialogs/coach_rating_dialog.dart';
import 'bloc/coach_profile_bloc.dart';
import 'models/profile_model.dart';
import 'package:flutter/material.dart';
import 'package:syria_sports/core/app_export.dart';
import 'package:syria_sports/widgets/app_bar/appbar_subtitle.dart';
import 'package:syria_sports/widgets/app_bar/custom_app_bar.dart';

class CoachProfileScreen extends StatelessWidget {
  final User user;
  const CoachProfileScreen({Key? key, required this.user}) : super(key: key);

  static Widget builder(BuildContext context , User user) {
    return BlocProvider<ProfileBloc>(
        create: (context) =>
            ProfileBloc(ProfileState())
              ..add(ProfileInitialEvent()),
        child: CoachProfileScreen(user: user,));
  }

  @override
  Widget build(BuildContext context) {
    mediaQueryData = MediaQuery.of(context);
    return BlocBuilder<ProfileBloc, ProfileState>(builder: (context, state) {
      dynamic rate = num.tryParse(user.rate??'0.0')??0.0;
      rate = rate.toStringAsFixed(1);
      return Scaffold(
        appBar: AppBar(
          shadowColor: Colors.transparent,
          toolbarHeight: 0,
        ),
        body: SingleChildScrollView(
          physics: const AlwaysScrollableScrollPhysics(),
          child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                SizedBox(
                  height: mediaQueryData.size.height/3,
                  width:mediaQueryData.size.width,
                  child: Stack(
                    children: [
                      Container(
                        height: mediaQueryData.size.height/3,
                        width:mediaQueryData.size.width,
                        decoration: BoxDecoration(
                            color: Colors.black26,
                            borderRadius: const BorderRadius.only(
                              bottomLeft: Radius.circular(32),
                            ),
                            image: DecorationImage(
                              fit:(user.image== null)?null: BoxFit.cover,
                              image:(user.image== null)?Image.asset(ImageConstant.imgLogo).image : Image.network(user.image!).image,
                            )
                        ),
                      ),
                      Align(
                        alignment: Alignment.bottomRight,
                        child: Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: Container(
                            height: 28,
                            width: 100,
                            padding:const EdgeInsets.all(4),
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                              color: Colors.white70,
                              borderRadius: BorderRadius.circular(99),
                            ),
                            child: Text('التقييم:$rate%',style: theme.textTheme.displayMedium!.copyWith(color: Colors.black),),
                          ),
                        ),
                      ),
                      Align(
                        alignment: Alignment.topRight,
                        child: Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: OutlineIconButton(
                            imagePath: ImageConstant.imgRightIcon,
                            onTapped: (){
                              Navigator.pop(context);
                            },
                          ),
                        ),
                      ),
                    ],
                  ),
            ),
                const SizedBox(height: 8,),
                Align(
                    alignment: Alignment.centerRight,
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Text(
                        user.fullName,
                        style: theme.textTheme.titleSmall,
                      ),
                    ),
                ),
                if(PrefUtils.isCoach())
                Align(
                  alignment: Alignment.centerRight,
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Text(
                      user.username??'',
                      style: theme.textTheme.titleSmall,
                    ),
                  ),
                ),
                SizedBox(height: 8.v),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: SizedBox(
                      width: mediaQueryData.size.width,
                      child: Text(
                        user.description ?? "",
                        style: theme.textTheme.bodySmall,
                      ),
                  ),
                ),

            ListTile(
                  leading: const Icon(Icons.phone, color: Color(0xffbdbab9)),
                  title: const Text("رقم الهاتف:",style: TextStyle(fontSize: 14),),
                  subtitle: SelectableText(user.phone??"لا يوجد",style: const TextStyle(color: Color(0xffbdbab9)),),
                  trailing: Column(
                    children: [
                      if(PrefUtils.isLogged())
                        InkWell(
                          onTap: (){
                            //if(kDebugMode) {
                              showDialog(
                              context: context,
                              builder: (BuildContext context) {
                                return CoachRatingDialog(coach: user);
                              },
                            );
                            /*}else{
                              showMessage('هذه الخدمة غير متاحة في الاصدار التجريبي');
                            }*/

                          },
                          child: const Column(
                            children: [
                              Icon(
                                Icons.star_rate_outlined,
                                color: Colors.red,
                              ),
                              SizedBox(height: 4),
                              Text("ارسل تقييم",style: TextStyle(color: Color(0xffbdbab9),fontSize: 14),),
                            ],
                          ),
                        ),
                    ],
                  ),
                ),

                /*ListTile(
                  leading: const Icon(Icons.email, color: Colors.white54),
                  title: const Text("البريد الالكتروني:",style: TextStyle(fontSize: 14),),
                  subtitle: SelectableText(user.phone??"لا يوجد",style: const TextStyle(color: Color(0xffbdbab9)),),
                  //trailing: Icon(Icons.copy, color: Colors.white54),
                ),*/
                /*_buildProfileDetailOption(context,
                        dateIcon: ImageConstant.imgGenderIcon,
                        birthdayText: "lbl_gender".tr,
                        birthDateValue: "lbl_male".tr),
                    _buildProfileDetailOption(context,
                        dateIcon: ImageConstant.imgDateIcon,
                        birthdayText: "lbl_birthday".tr,
                        birthDateValue: "lbl_12_12_2000".tr),
                    _buildProfileDetailOption(context,
                        dateIcon: ImageConstant.imgMailPrimary,
                        birthdayText: "lbl_email".tr,
                        birthDateValue: "msg_rex4dom_gmail_com".tr),
                    _buildProfileDetailOption(context,
                        dateIcon: ImageConstant.imgCreditCardIcon,
                        birthdayText: "lbl_phone_number".tr,
                        birthDateValue: "lbl_307_555_0133".tr),
                    SizedBox(height: 5.v),
                    _buildProfileDetailOption(context,
                        dateIcon: ImageConstant.imgLockPrimary,
                        birthdayText: "lbl_change_password".tr,
                        birthDateValue: "msg".tr,
                        onTapProfileDetailOption: () {
                      onTapProfileDetailOption(context);
                    }),*/

              ]),
        ),
      );
    });
  }

  /// Section Widget
  PreferredSizeWidget _buildAppBar(BuildContext context) {
    return CustomAppBar(
        leading: OutlineIconButton(
          imagePath: ImageConstant.imgRightIcon,
          onTapped: (){
            Navigator.pop(context);
          },
        ),
        title: AppbarSubtitle(
            text: "lbl_profile".tr, margin: EdgeInsets.only(left: 12.h)));
  }

}
